#!/usr/bin/env python
# encoding: utf-8
# Date: 2017-07-31
# file:models.py
# Email: wang521kang@outlook.com
# Author: 王康
from django.db import models


class Commodity(models.Model):
    name = models.CharField(max_length=255, verbose_name=u'商品名称')
    price = models.IntegerField(default=0, verbose_name=u'商品单价')
    preferential = models.CharField(max_length=255, null=True, verbose_name=u'商品优惠')
    type = models.ForeignKey('Type', verbose_name=u'商品分类主键')


class CommodityImg(models.Model):
    commodity = models.ForeignKey(Commodity, verbose_name=u'商品主键')
    img_url = models.CharField(max_length=255, blank=True, null=True, verbose_name=u'图片地址')
    is_active = models.BooleanField(default=True, verbose_name=u'是否删除')


class Property(models.Model):
    commodity = models.ForeignKey(Commodity, verbose_name=u'商品主键')
    property = models.CharField(max_length=255, verbose_name=u'商品规格名')


class Value(models.Model):
    property = models.ForeignKey(Property, verbose_name=u'商品规格名主键')
    value = models.CharField(max_length=255, verbose_name=u'商品规格')


class Type(models.Model):
    type = models.CharField(max_length=255, verbose_name=u'商品分类')
    px = models.IntegerField(default=0, verbose_name=u'分类排序')


class Purchase(models.Model):
    commodity = models.ForeignKey(Commodity, verbose_name=u'商品主键')
    num = models.IntegerField(verbose_name=u'采购数量', default=0)
    company = models.CharField(verbose_name=u'进货公司', max_length=255)
    unit = models.ForeignKey('Unit', verbose_name=u'单位主键')


class Unit(models.Model):
    unit = models.CharField(max_length=255, verbose_name=u'单位')


class WareHouse(models.Model):
    name = models.CharField(max_length=255, verbose_name=u'仓库名称')
    commodities = models.ManyToManyField(Commodity, verbose_name=u'商品主键')
